Skip to content

Add support for Enum's implementing CustomType<EnumName>#68

Closed
ThoSap wants to merge 7 commits into
mainfrom
add-support-for-enums-implementing-custom-type
Closed

Add support for Enum's implementing CustomType<EnumName>#68
ThoSap wants to merge 7 commits into
mainfrom
add-support-for-enums-implementing-custom-type

Conversation

@ThoSap
Copy link
Copy Markdown
Member

@ThoSap ThoSap commented May 6, 2026

In Finstral, we have a case where the Enum is the EntityId (e.g. CustomType) -> for example the Authority enum

@ThoSap ThoSap self-assigned this May 6, 2026
@ThoSap ThoSap requested a review from SirCotare May 6, 2026 16:26
@ThoSap ThoSap force-pushed the add-support-for-enums-implementing-custom-type branch from 478d3d2 to 920281b Compare May 6, 2026 16:53
@ThoSap ThoSap removed the request for review from SirCotare May 6, 2026 17:13
@ThoSap
Copy link
Copy Markdown
Member Author

ThoSap commented May 6, 2026

I'm closing this as it makes more sense to do

@NullMarked
public enum DirectEnumEntityId {
    VAL1,
    VAL2;

    public ID asId() {
        return new ID(this);
    }

    public record ID(
            DirectEnumEntityId value
    ) implements EntityId<DirectEnumEntityId>, Comparable<ID> {
        ID(ID other) {
            this(other.value());
        }

        @Override
        public String toString() {
            return String.valueOf(value());
        }

        @Override
        public int compareTo(ID other) {
            return value().name().compareTo(other.value().name());
        }
    }
}

instead of

@NullMarked
public enum DirectEnumEntityId implements EntityId<DirectEnumEntityId> {
    VAL1,
    VAL2;

    @Override
    public DirectEnumEntityId value() {
        return this;
    }
}

which this PR tried to support.

@ThoSap ThoSap closed this May 6, 2026
@SirCotare
Copy link
Copy Markdown
Member

SirCotare commented May 7, 2026

I think you are right. The first approach still differentiates between the enum and the ID class. So it is not trying to cater to both concerns at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants